﻿namespace PowerSong.UserInterface
    {
    using System.Windows;
    using System.Linq;
    using PowerSong.SongDatabase;

    /// <summary>
    /// Interaction logic for ViewCategorySongsWindow.xaml
    /// </summary>
    public partial class ViewCategorySongsWindow : Window
        {

        private Category category = null;

        public ViewCategorySongsWindow(Category category)
            {
            InitializeComponent();
            this.CategoryNameTextBox.Text = category.Name;
            this.category = category;
            UpdateSongList();
            }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
            {
            this.DialogResult = true;
            }

        private void UpdateSongList()
            {
            SongsListBox.Items.Clear();
            var songs = State.Database.Categories.GetSongs(category).OrderBy(song => song.Title);
            foreach (var song in songs)
                {
                SongsListBox.Items.Add(song);
                }
            }

        }

    }
